<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>工作总结申请</title>
    <script src="../../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../../res/js/Tools.js" charset="utf-8"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../../res/images/favicon.ico">
    <link rel="stylesheet" href="../../../../../res/layui/css/layui.css" media="all">
</head>
<script>
    $.ajaxSetup({
        async: false
    });
</script>
<body style="padding: 10px">
<div style="display: none" id="bodys">
    <form action="" class="layui-form layui-form-pane" lay-filter="example">
        <h1 align="center" style="margin-bottom: 20px">工作总结</h1>
        <!--流程id-->
        <input name="pkWorkSummaryId" id="pkWorkSummaryId" type="hidden"/>
        <!--员工id-->
        <input name="personnelId" id="personnelId" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">总结类型</label>
            <div class="layui-input-block">
                <div id="workSummaryTypeSuperior" class="xm-select-demo"></div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">本阶段总结</label>
            <div class="layui-input-block">
            <textarea style="height: 300px" placeholder="请输入内容" class="layui-textarea" id="workSummaryContent"
                      name="workSummaryContent" lay-verify="required">一、今日工作完成情况
            1、
            2、
            3、

二、今日新增任务
            1、
            2、
            3、

三、需提示其他部门协同事项（如有）
            1、
            2、
            </textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">总结说明</label>
                <div class="layui-input-block">
                    <input type="text" name="workSummaryExplain" id="workSummaryExplain" lay-verify="required" autocomplete="off" placeholder="请输入(必填)" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">下阶段计划</label>
            <div class="layui-input-block">
            <textarea style="height: 150px" placeholder="请输入内容" class="layui-textarea" id="nextPeriodContent"
                      name="nextPeriodContent" lay-verify="required">四、计划明日完成任务
            1、
            2、
            3、
            </textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">计划说明</label>
                <div class="layui-input-block">
                    <input type="text" name="nextPeriodExplain" id="nextPeriodExplain" lay-verify="required" autocomplete="off" placeholder="请输入（必填）" class="layui-input">
                </div>
            </div>
        </div>

        <!-- 提交-->
        <div class="layui-form-item" id="sub">
            <div class="layui-input-block" id="flows">
                <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1">立即提交</button>
                <input type="button" class="layui-btn  layui-btn-primary" id="deleteById" value="取消"/>
            </div>
        </div>
    </form>

</div>
<script>
    let pkWorkSummaryId = getQueryString("pkWorkSummaryId");
    let show = getQueryString("show");
    let pkWorkSummaryTypeId;
    let disabled = false;
    layui.use(['form', 'laydate', 'table'], function () {
        var table = layui.table
            ,form = layui.form
            , layer = layui.layer;

        let res;
        if (pkWorkSummaryId) {
            res = getAjaxById(getRootPath() + "OaWorkSummaryAction/findById/" + pkWorkSummaryId);
            //工作总结id
            $("#pkWorkSummaryId").val(res.pkWorkSummaryId);
            //工作总结类型
            pkWorkSummaryTypeId=res.workSummaryTypeId;
            //本阶段总结
            let workSummaryContent = $("#workSummaryContent");
            workSummaryContent.val(res.workSummaryContent);
            //本阶段说明
            let workSummaryExplain = $("#workSummaryExplain");
            workSummaryExplain.val(res.workSummaryExplain);
            //下阶段计划
            let nextPeriodContent = $("#nextPeriodContent");
            nextPeriodContent.val(res.nextPeriodContent);
            //下阶段计划说明
            let nextPeriodExplain = $("#nextPeriodExplain");
            nextPeriodExplain.val(res.nextPeriodExplain);

            //判断是否是查看
            if(show){
                disabled = true;
                //本阶段总结
                formDisabled(workSummaryContent);
                //本阶段说明
                formDisabled(workSummaryExplain);
                //下阶段计划
                formDisabled(nextPeriodContent);
                //下阶段计划说明
                formDisabled(nextPeriodExplain);
                //隐藏提交按钮
                $("#sub").hide();

            }
            form.render();
        }

        //加载组件
        layui.config({
            //引入扩展文件库
            base: getRootPath()+'res/layui/dist/'
        }).extend({
            //引入对应的文件名
            xmSelect: 'xm-select'
            //拿到对应的文件模块
        }).use(['xmSelect'], function(){
            //对于模块赋值使用
            var xmSelect = layui.xmSelect;
            //渲染多选
            pkJurisdictionId = xmSelect.render({
                el: '#workSummaryTypeSuperior',
                radio: true,
                disabled: disabled,
                tree: {
                    show: true,
                    strict: false,
                    expandedKeys: [ -1 ],
                },
                height: 'auto',
                data: loadWorkSummaryType(pkWorkSummaryTypeId,show)
            })

        });

        function loadWorkSummaryType(id,show){
            let url = getRootPath()+"OaWorkSummaryTypeAction/loadWorkSummaryType";
            let data = {
                id : id,
                show:"1"
            };
            let res = getAjax(url,data);
            if(res){
                return res;
            }else{
                return [];
            }
        }

        /*let data=getAjaxById(getRootPath()+"OaRegularFlowAction/isExist");
        if(data){
            //墨绿深蓝风
            layer.alert('你已提交转正申请请勿重复提交', {
                skin: 'layui-layer-molv' //样式类名
                ,closeBtn: 0
            }, function(){
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        }*/

        form.render();

        //监听起草提交
        form.on('submit(demo1)', function (data) {
            /*data={
                affirmTime:$("#affirmTime").val(),
                personnelId:$("#personnelId").val()
            };*/
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            const res = postAjax(getRootPath() + "OaWorkSummaryAction/add", data.field);
            if (res.code === 1) {
                layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面
                    //window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3000);
                //window.location.reload();//刷新页面
            } else if (res.code === 500) {
                error('500');
            } else {
                layer.msg("新增失败");
            }
            return false;
        });

        $("#deleteById").on("click",function () {
            //询问框
            layer.confirm('是否取消工作总结', {
                btn: ['确认','取消'] //按钮
            }, function(){
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                //window.parent.location.reload();//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });

        });
        /**
         * 禁用
         *  @param forms 控件
         */
        function formDisabled(forms) {
            const DISABLED = 'layui-btn-disabled';
            forms.attr('disabled', 'disabled');
            forms.addClass(DISABLED);
        }


        $("#bodys").show();
        form.render();
    });
</script>
</body>
</html>